import sqlite3
class DBase:
    
    def __init__(self, fileName, createQuery):
        self.fileName = fileName
        self.connection = sqlite3.connect(fileName)
        self.connection.row_factory = sqlite3.Row
        self.row = None
        
        self.cursor = self.connection.cursor()
        
        self.cursor.execute(createQuery)
        
        self.connection.isolation_level = None
        self.connection.commit()
        
    def UserExists(self, table, field, user):
        found = False
        self.cursor.execute(self.userExistsQuery(table, field, user))
        self.row = self.cursor.fetchone()
        found = True if (self.row is not None) else False
        
        return found
    
    def userExistsQuery(self, table, userField, user):
        return  ("SELECT " + userField + "\
        FROM " + table + " \
        WHERE " + userField + " = \"%s\" "% (user))
        
    def GetFileName(self):
        return self.fileName
